package com.rmt.www.daoImpl;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;

import com.rmt.www.dao.RequirementArtifactHistoryDao;
import com.rmt.www.vo.FeatureArtifactHistory;
import com.rmt.www.vo.RequirementArtifactHistory;

public class RequirementArtifactHistoryDaoImpl implements RequirementArtifactHistoryDao {

	private JdbcTemplate jdbcTemplate;

	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}
	
	@SuppressWarnings("unchecked")
	public List<RequirementArtifactHistory> getRequirementArtifactHistoryById(int id) {
		return (List<RequirementArtifactHistory>)(this.jdbcTemplate.query("select * from requirementartifacthistory where requirementartifactid=?",
				new Object[]{id}, 
				new int[]{java.sql.Types.INTEGER}, 
				new RequirementArtifactHistoryRowMapper()));
	}

	public void insertRequirementArtifactHistory(RequirementArtifactHistory newHistory) {
		jdbcTemplate.update("insert into requirementartifacthistory(pid,title,authorid,version,priority,source,rational,createdtime,updaterid,updatedtime,status,description,cost,effort,risk,updatedtimes,requirementtype,requirementartifactid) " +
				"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", 
		new Object[]{
			newHistory.getPid(),
			newHistory.getTitle(),
			newHistory.getAuthorId(),
			newHistory.getVersion(),
			newHistory.getPriority(),
			newHistory.getSource(),
			newHistory.getRational(),
			newHistory.getCreatedtime(),
			newHistory.getUpdateUserId(),
			newHistory.getUpdatedtime(),
			newHistory.getStatus(),
			newHistory.getDescription(),
			newHistory.getCost(),
			newHistory.getEffort(),
			newHistory.getRisk(),
			newHistory.getUpdatedtimes(),
			newHistory.getRequirementtype(),
			newHistory.getRequirementartifactid()
		},new int[] {
				java.sql.Types.INTEGER,
				java.sql.Types.VARCHAR,
				java.sql.Types.INTEGER,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.TIMESTAMP,
				java.sql.Types.INTEGER,
				java.sql.Types.TIMESTAMP,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.INTEGER,
				java.sql.Types.VARCHAR,
				java.sql.Types.INTEGER,
				java.sql.Types.VARCHAR,
				java.sql.Types.INTEGER
		});

	}

}
